package cn.gson.fengboot.model.service;


import cn.gson.fengboot.model.dao.*;
import cn.gson.fengboot.model.mapper.QproductMapper;
import cn.gson.fengboot.model.pojos.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class QproductService {
    @Autowired
    QproductMapper proMapper;
    @Autowired
    QproductdetailQmodeldetailsDao qproductdetailQmodeldetailsDao;
    @Autowired
    QproductdetailDao productdetailDao;@Autowired
    QproductDao productDao;
    @Autowired
    QmodeldetailsDao modeldetailsDao;
    @Autowired
    QpictureDao pictureDao;
    //查询
    public List<Qproduct> qproductList(String input){
        return proMapper.allpro(input);
    }

    //新增
    public  void addkhtousu(Qxinz qxinz){
        Qproductdetail productdetail = new Qproductdetail();
        productdetail.setProdetailId(qxinz.getProdetailId());
        productdetail.setProdetailBh(qxinz.getProdetailBh());
        productdetail.setProdetaiJpri(qxinz.getProdetaiJpri());
        productdetail.setProdetailSpri(qxinz.getProdetailSpri());
        productdetail.setProdetailKcnum(qxinz.getProdetailKcnum());
        productdetail.setPicturePath(qxinz.getPicturePath());
        productdetail.setProductName(qxinz.getProductName());
        productdetail.setTypeId(new QtypeEntity(qxinz.getTypeId()));
        Qproductdetail save = productdetailDao.save(productdetail);
        List<Integer[]> guigezhi = qxinz.getGuigezhi();
        QproductdetailQmodeldetails qproductdetailQmodeldetails =null;
        //获取规格值id
        for (Integer[] obj:guigezhi ) {
            for(int i = 0; i < obj.length; i++){
                if(i %2 == 1 ){
                    qproductdetailQmodeldetails = new QproductdetailQmodeldetails();
                    qproductdetailQmodeldetails.setModetId(obj[i]);
                    qproductdetailQmodeldetails.setProdetailId(save.getProdetailId());
                    qproductdetailQmodeldetailsDao.save(qproductdetailQmodeldetails);
                    System.out.println(obj[i]);
                }
            }
        }
    }
    //删除
    public void deleteproduct(int id){
        productdetailDao.deleteById(id);
    }

}
